﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLT_Public;
using QLT_BLL;

namespace GiaoDien
{
    public partial class frm_Thuoc_LoaiThuoc_Them : DevExpress.XtraEditors.XtraForm
    {
        public frm_Thuoc_LoaiThuoc_Them()
        {
            InitializeComponent();
        }
        private int _Flag;

        public int Flag
        {
            get { return _Flag; }
            set { _Flag = value; }
        }
        private int _MaLoaiThuoc;

        public int MaLoaiThuoc
        {
            get { return _MaLoaiThuoc; }
            set { _MaLoaiThuoc = value; }
        }
        private string _TenLoaiThuoc;

        public string TenLoaiThuoc
        {
            get { return _TenLoaiThuoc; }
            set { _TenLoaiThuoc = value; }
        }
        private string _GhiChu;

        public string GhiChu
        {
            get { return _GhiChu; }
            set { _GhiChu = value; }
        }
        LoaiThuoc_BLL loaithuoc_bll = new LoaiThuoc_BLL();
        public void GetData()
        {
            txt_MaLoaiThuoc.Text = MaLoaiThuoc.ToString();
            txt_TenLoaiThuoc.Text = TenLoaiThuoc;
            txt_GhiChu.Text = GhiChu;
        }
        public void LoadForm()
        {
            if (Flag == 0)
            {
                this.Text = "Thêm Mới Loại Thuốc";
                txt_MaLoaiThuoc.Text = "Mã tự sinh";
                txt_MaLoaiThuoc.Enabled = false;
            }
            if (Flag == 1)
            {
                this.Text = "Sửa Thông Tin Loại Thuốc";
                GetData();
            }
        }
        public delegate void GetInt(int kt);
        public GetInt MyLoad;
        private void frm_Thuoc_LoaiThuoc_Them_Load(object sender, EventArgs e)
        {
            LoadForm();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            LoaiThuoc_Public lt = new LoaiThuoc_Public();
            if (Flag == 0)
            {
                //them moi
                lt.TenLoaiThuoc = txt_TenLoaiThuoc.Text;
                lt.GhiChu = txt_GhiChu.Text;
                loaithuoc_bll.insert_LoaiThuoc(lt,lt);
                XtraMessageBox.Show("Thêm mới thành công!","Thông Báo",MessageBoxButtons.OK,MessageBoxIcon.Information);
                btnHuy_Click(sender,e);

            }
            if (Flag == 1)
            {
               //sua
                lt.MaLoaiThuoc = int.Parse(txt_MaLoaiThuoc.Text);
                lt.TenLoaiThuoc = txt_TenLoaiThuoc.Text;
                lt.GhiChu = txt_GhiChu.Text;
                loaithuoc_bll.update_LoaiThuoc(lt,lt, lt);
                XtraMessageBox.Show("Sửa thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                btnHuy_Click(sender, e);
            }
            MyLoad(1);
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            txt_MaLoaiThuoc.Text = "";
            txt_TenLoaiThuoc.Text = "";
            txt_GhiChu.Text = "";
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}